package c.francis.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import c.francis.pojo.Member;
import c.francis.service.impl.MemberServiceImpl;
import c.francis.utils.CookieUtils;
import c.francis.utils.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {

//	@Autowired
//	private HostHolder	hostHolder;

	@Autowired
	private MemberServiceImpl	memberService;

	@RequestMapping("/gohome")
	public String gethome() {
		return "homepage";
	}


	@RequestMapping("/out")
	public String otuhome(HttpServletRequest request) {

		String ticket = CookieUtils.getValue(request, "ticket");
		Member member = memberService.findMemberByTicket(ticket);
		memberService.updateTicketByEmail(member.getEmail(),"0");


		//HttpSession session = request.getSession();
		//session.removeAttribute("member");

		return "homepage";
	}

	@GetMapping("/goindex")
	public String	goIndex( /**Model model*/){

		//Member member = hostHolder.getUser();
//
//		model.addAttribute("member",member);
//		model.addAttribute("user","zhangsan");
//
//		System.out.println("---------godindex------"+member);

		return "index";
	}
	
	@RequestMapping("outadmin")
	public String outadmin(HttpSession session) {
		session.removeAttribute("manager");
		return "admin_login";
	}
}
